﻿namespace Trader.Analyzing
{
    using System;
    using System.Collections.Generic;
    using BO.Interface;
    using Interface;

    public class ScenariosGenerator
    {
        private const int periodDays = 12;
        private readonly int numOfRanges;

        public ScenariosGenerator(int numOfRanges)
        {
            this.numOfRanges = numOfRanges;
        }

        public IScenarios Generate(IStock stock, IActionPoints actionPoints)
        {
            var builder = new ScenariosBuilder(numOfRanges);

            foreach (DateTime startDate in actionPoints)
            {
                var periodChanges = new List<decimal>(periodDays);
                decimal startQuote = stock.Quotes[startDate].Closing;
                for (int i = 0; i <= periodDays; i++)
                {
                    decimal closing = stock.Quotes[startDate + TimeSpan.FromDays(i)].Closing;
                    periodChanges.Add(closing/startQuote - 1M);
                }
                builder.Add(periodChanges);
            }

            return builder.GetScenarios();
        }
    }
}